﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MidApp
{
    public class ManageTopic
    {
        /// <summary>
        ///Metoda vraci temata ve foru patrici tymu.
        /// </summary>
        public static List<AppLib.Topic> GetThreadsBelongingToTeam(int TeamID)
        {
            var db = MidApp.LinqUse.DBConn;
            return (from Topic in db.Topics where Topic.TeamID==TeamID orderby Topic.Inserted descending select Topic).ToList();
        }
        /// <summary>
        ///Metoda vytvori nove tema ve foru tymu.
        /// </summary>
        public static void CreateNewTopic(AppLib.Topic newTopic)
        {
            var db = MidApp.LinqUse.DBConn;

            db.Topics.InsertOnSubmit(newTopic);
            db.SubmitChanges();

        }
        /// <summary>
        ///Metoda vrati tema o zadanem ID.
        /// </summary>
        public static AppLib.Topic GetThread(int ThreadID)
        {
            var db = MidApp.LinqUse.DBConn;

            return (from Topic in db.Topics where Topic.ThreadID == ThreadID select Topic).First();
        }
        /// <summary>
        ///Metoda vrati tema o nazvu vlozeneho za data.
        /// </summary>
        public static AppLib.Topic GetThreadByNameAndDate(string Title, DateTime Date)
        {
            var db = MidApp.LinqUse.DBConn;

            return (from Topic in db.Topics where Topic.Title == Title && Topic.Inserted.Equals(Date) select Topic).First();
        }
        /// <summary>
        ///Metoda vrati tema o zadanem ID.
        /// </summary>
        public static List<AppLib.Topic> GetThreadByAuthorAndTeam(int TeamID, int UserID)
        {
            var db = MidApp.LinqUse.DBConn;

            return (from Topic in db.Topics where Topic.UserID == UserID && Topic.TeamID==TeamID orderby Topic.Inserted descending select Topic).ToList();
        }
    }
}
